1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.google.common.collect.testing.testers;
18
19 import static com.google.common.collect.testing.features.CollectionSize.ZERO;
20 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEYS;
21 import static com.google.common.collect.testing.features.MapFeature.ALLOWS_NULL_KEY_QUERIES;
22
23 import com.google.common.annotations.GwtCompatible;
24 import com.google.common.collect.testing.AbstractMapTester;
25 import com.google.common.collect.testing.WrongType;
26 import com.google.common.collect.testing.features.CollectionSize;
27 import com.google.common.collect.testing.features.MapFeature;
28
29
30
31
32
33
34
35
36 @GwtCompatible
37 public class MapContainsKeyTester<K, V> extends AbstractMapTester<K, V> {
38 @CollectionSize.Require(absent = ZERO)
39 public void testContains_yes() {
40 assertTrue("containsKey(present) should return true",
41 getMap().containsKey(samples.e0.getKey()));
42 }
43
44 public void testContains_no() {
45 assertFalse("containsKey(notPresent) should return false",
46 getMap().containsKey(samples.e3.getKey()));
47 }
48
49 @MapFeature.Require(ALLOWS_NULL_KEY_QUERIES)
50 public void testContains_nullNotContainedButAllowed() {
51 assertFalse("containsKey(null) should return false",
52 getMap().containsKey(null));
53 }
54
55 @MapFeature.Require(absent = ALLOWS_NULL_KEY_QUERIES)
56 public void testContains_nullNotContainedAndUnsupported() {
57 expectNullKeyMissingWhenNullKeysUnsupported(
58 "containsKey(null) should return false or throw");
59 }
60
61 @MapFeature.Require(ALLOWS_NULL_KEYS)
62 @CollectionSize.Require(absent = ZERO)
63 public void testContains_nonNullWhenNullContained() {
64 initMapWithNullKey();
65 assertFalse("containsKey(notPresent) should return false",
66 getMap().containsKey(samples.e3.getKey()));
67 }
68
69 @MapFeature.Require(ALLOWS_NULL_KEYS)
70 @CollectionSize.Require(absent = ZERO)
71 public void testContains_nullContained() {
72 initMapWithNullKey();
73 assertTrue("containsKey(null) should return true",
74 getMap().containsKey(null));
75 }
76
77 public void testContains_wrongType() {
78 try {
79
80 assertFalse("containsKey(wrongType) should return false or throw",
81 getMap().containsKey(WrongType.VALUE));
82 } catch (ClassCastException tolerated) {
83 }
84 }
85 }